package com.xmy.solution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xmy.common.annotation.Log;
import com.xmy.common.core.controller.BaseController;
import com.xmy.common.core.domain.AjaxResult;
import com.xmy.common.enums.BusinessType;
import com.xmy.solution.domain.Categories;
import com.xmy.solution.service.IcategoriesService;
import com.xmy.common.utils.poi.ExcelUtil;
import com.xmy.common.core.page.TableDataInfo;

/**
 * 方案分类Controller
 *
 * @author 夏明毅
 * @date 2024-12-28
 */
@RestController
@RequestMapping("/solution/categories")
public class categoriesController extends BaseController {
    @Autowired
    private IcategoriesService categoriesService;

    /**
     * 查询方案分类列表
     */
    @PreAuthorize("@ss.hasPermi('solution:categories:list')")
    @GetMapping("/list")
    public TableDataInfo list(Categories categories) {
        startPage();
        List<Categories> list = categoriesService.selectcategoriesList(categories);
        return getDataTable(list);
    }
    @GetMapping("/AppList")
    public TableDataInfo AppList() {
        startPage();
        List<Categories> list = categoriesService.selectcategoriesList(new Categories());
        return getDataTable(list);
    }

    /**
     * 导出方案分类列表
     */
    @PreAuthorize("@ss.hasPermi('solution:categories:export')")
    @Log(title = "方案分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Categories categories) {
        List<Categories> list = categoriesService.selectcategoriesList(categories);
        ExcelUtil<Categories> util = new ExcelUtil<Categories>(Categories.class);
        util.exportExcel(response, list, "方案分类数据");
    }

    /**
     * 获取方案分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('solution:categories:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(categoriesService.selectcategoriesById(id));
    }

    /**
     * 新增方案分类
     */
    @PreAuthorize("@ss.hasPermi('solution:categories:add')")
    @Log(title = "方案分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Categories categories) {
        return toAjax(categoriesService.insertCategories(categories));
    }

    /**
     * 修改方案分类
     */
    @PreAuthorize("@ss.hasPermi('solution:categories:edit')")
    @Log(title = "方案分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Categories categories) {
        return toAjax(categoriesService.updatecategories(categories));
    }

    /**
     * 删除方案分类
     */
    @PreAuthorize("@ss.hasPermi('solution:categories:remove')")
    @Log(title = "方案分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(categoriesService.deletecategoriesByIds(ids));
    }
}
